Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethersproject/bignumber

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/bignumber

BigNumber library used in ethers.js.

  • 5.7.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
996K
increased by2.41%
Maintainers
1
Weekly downloads
 
Created

What is @ethersproject/bignumber?

@ethersproject/bignumber is a library for handling large numbers in JavaScript, particularly useful in the context of Ethereum and blockchain development. It provides utilities for creating, manipulating, and performing arithmetic operations on big numbers, which are common in blockchain transactions and smart contracts.

What are @ethersproject/bignumber's main functionalities?

Creating Big Numbers

This feature allows you to create big numbers from strings, numbers, or hex values. The example demonstrates creating a BigNumber instance from a string and converting it back to a string for display.

const { BigNumber } = require('@ethersproject/bignumber');
const bigNumber = BigNumber.from('12345678901234567890');
console.log(bigNumber.toString());

Arithmetic Operations

This feature provides methods for performing arithmetic operations such as addition, subtraction, multiplication, and division on BigNumber instances. The example shows how to add two BigNumber instances.

const { BigNumber } = require('@ethersproject/bignumber');
const a = BigNumber.from(10);
const b = BigNumber.from(20);
const sum = a.add(b);
console.log(sum.toString());

Comparison Operations

This feature includes methods for comparing BigNumber instances, such as less than (lt), greater than (gt), and equals (eq). The example demonstrates comparing two BigNumber instances.

const { BigNumber } = require('@ethersproject/bignumber');
const a = BigNumber.from(10);
const b = BigNumber.from(20);
console.log(a.lt(b)); // true
console.log(a.eq(b)); // false

Formatting and Parsing

This feature allows you to format BigNumber instances to different string representations, such as hexadecimal. The example shows how to convert a BigNumber to a hex string.

const { BigNumber } = require('@ethersproject/bignumber');
const bigNumber = BigNumber.from('12345678901234567890');
const formatted = bigNumber.toHexString();
console.log(formatted);

Other packages similar to @ethersproject/bignumber

Keywords

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc